package com.youbug.mall.coupon_sms.controller;


import com.youbug.common.vo.QueryVo;
import com.youbug.mall.coupon_sms.entity.SmsSeckillSession;
import com.youbug.mall.coupon_sms.entity.SmsSeckillSkuRelation;
import com.youbug.mall.coupon_sms.service.ISmsSeckillSessionService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youbug.mall.coupon_sms.service.ISmsSeckillSkuRelationService;
import org.springframework.web.bind.annotation.*;
import com.youbug.common.vo.R;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 秒杀活动场次 前端控制器
 * </p>
 *
 * @author youbug
 * @since 2024-07-20
 */
@RestController
@RequestMapping("/smsSeckillSession")
public class SmsSeckillSessionController {

    @Autowired
    private ISmsSeckillSkuRelationService smsSeckillSkuRelationService;
    @Autowired
    private ISmsSeckillSessionService smsSeckillSessionService;

    @PostMapping("/getSmsSeckillSessionPage")
    public R<IPage<SmsSeckillSession>> getSmsSeckillSessionPage(@RequestBody QueryVo<SmsSeckillSession> queryVo){

        IPage<SmsSeckillSession> smsSeckillSessions = smsSeckillSessionService.getSmsSeckillSessionPage(queryVo);

        return R.ok(smsSeckillSessions);
    }

    @GetMapping("/getSmsSeckillSessionById/{id}")
    public R<SmsSeckillSession> getSmsSeckillSessionById(@PathVariable Long id){

        SmsSeckillSession smsSeckillSession = smsSeckillSessionService.getById(id);

        return R.ok(smsSeckillSession);
    }

    @PostMapping("/add")
    public R<Boolean> add(@RequestBody SmsSeckillSession smsSeckillSession){

        boolean save = smsSeckillSessionService.save(smsSeckillSession);

        return  R.ok(save);
    }

    @PostMapping("/update")
    public R<Boolean> update(@RequestBody SmsSeckillSession smsSeckillSession){

        boolean update = smsSeckillSessionService.updateById(smsSeckillSession);

        return  R.ok(update);
    }

    @GetMapping("/delete/{id}")
    public R<Boolean> delete(@PathVariable Long id){

        boolean remove = smsSeckillSessionService.removeById(id);

        return  R.ok(remove);
    }

    @GetMapping("/getSmsSeckillSkuRelationBySessionId/{id}")
    public R<IPage<SmsSeckillSkuRelation>> getSmsSeckillSkuRelationById(@PathVariable Long id){

        QueryVo<SmsSeckillSkuRelation> queryVo = new QueryVo<>();

        SmsSeckillSkuRelation skuRelation = new SmsSeckillSkuRelation();

        skuRelation.setPromotionSessionId(id);

        queryVo.setPayload(skuRelation);

        IPage<SmsSeckillSkuRelation> relationIPage = smsSeckillSkuRelationService.getSmsSeckillSkuRelationPage(queryVo);

        return R.ok(relationIPage);
    }

    @PostMapping("/addSkuRelation")
    public R<Boolean> addSkuRelation(@RequestBody SmsSeckillSkuRelation smsSeckillSkuRelation){

        boolean save = smsSeckillSkuRelationService.save(smsSeckillSkuRelation);

        return  R.ok(save);
    }

    @PostMapping("/updateSkuRelation")
    public R<Boolean> updateSkuRelation(@RequestBody SmsSeckillSkuRelation smsSeckillSkuRelation){

        boolean update = smsSeckillSkuRelationService.updateById(smsSeckillSkuRelation);

        return  R.ok(update);
    }

    @GetMapping("/deleteSkuRelation/{id}")
    public R<Boolean> deleteSkuRelation(@PathVariable Long id){

        boolean remove = smsSeckillSkuRelationService.removeById(id);

        return  R.ok(remove);
    }
}

